package com.itheima.service.smsService.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.sms.SmsHomeRecommendSubject;
import com.itheima.mapper.smsMapper.SmsHomeRecommendSubjectMapper;
import com.itheima.service.smsService.SmsHomeRecommendSubjectService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SmsHomeRecommendSubjectServiceImpl implements SmsHomeRecommendSubjectService {

    @Autowired
    private SmsHomeRecommendSubjectMapper smsHomeRecommendSubjectMapper;

    //添加首页推荐专题
    @Override
    public void create(SmsHomeRecommendSubject smsHomeRecommendSubject) {

        smsHomeRecommendSubjectMapper.insert(smsHomeRecommendSubject);

    }
    //批量删除专题推荐推荐
    @Override
    public void deleteByid(Integer id) {

        smsHomeRecommendSubjectMapper.deleteById(id);

    }
    //查询总记录数
    @Override
    public Integer count() {

        LambdaQueryWrapper<SmsHomeRecommendSubject> qw = new LambdaQueryWrapper<>();

        return smsHomeRecommendSubjectMapper.selectCount(qw);
    }

    //条件分页查询
    @Override
    public List<SmsHomeRecommendSubject> list(Integer pageNum, Integer pageSize, String subjectName, Integer recommendStatus) {
        Page page = new Page<>(pageNum,pageSize);

        LambdaQueryWrapper<SmsHomeRecommendSubject> qw = new LambdaQueryWrapper<>();

        qw.like(subjectName!=null,SmsHomeRecommendSubject::getSubjectName,subjectName);
        qw.like(recommendStatus!=null,SmsHomeRecommendSubject::getRecommendStatus,recommendStatus);
        qw.orderByDesc(SmsHomeRecommendSubject::getSort);

        Page page1 = smsHomeRecommendSubjectMapper.selectPage(page, qw);

        return page1.getRecords();
    }

    //批量修改推荐状态
    @Override
    public void update(SmsHomeRecommendSubject smsHomeRecommendSubject) {

        smsHomeRecommendSubjectMapper.updateById(smsHomeRecommendSubject);

    }

    //修改推荐排序
    @Override
    public void updateBySort(SmsHomeRecommendSubject smsHomeRecommendSubject) {

        smsHomeRecommendSubjectMapper.updateById(smsHomeRecommendSubject);

    }
}
